﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiNing.UI.Controls;

namespace YiNing.Tools
{
    public class TestProgramConfig
    {
        /// <summary>
        /// 是否是非标的图谱
        /// </summary>
        public bool IsNonstandardMapping { get; set; }
        /// <summary>
        /// 输出脉冲宽度，也就是光源的亮度
        /// </summary>
        public int OutputPulseWidth { get; set; }
        public string Name { get; set; }

        /// <summary>
        /// 晶圆的编号信息
        /// </summary>
        public string Id { get; set; }
        public double DieWidth { get; set; }
        public double DieHeight { get; set; }
        /// <summary>
        /// 两个die的间隔X
        /// </summary>
        public double DieIntervalX { get; set; }
        /// <summary>
        /// 两个die的间隔Y
        /// </summary>
        public double DieIntervalY { get; set; }
        public int BestZPulseMain { get; set; }
        public double BestZPulseMainSensor { get; set; }
        public int[] BestZPulses = new int[6];  // 所有物镜的最佳高度
        public Die[,] Mapping { get; set; }

        /// <summary>
        /// 排除边沿芯片的个数
        /// </summary>
        public int ExcludeEdgeNum { get; set; }

        /// <summary>
        /// 晶圆的半径
        /// </summary>
        public double WaferRadius { get; set; }
        /// <summary>
        /// 切割道像素宽度
        /// </summary>
        public double CutRoadWidthPixel { get; set; }
        /// <summary>
        /// 切割道宽度微米
        /// </summary>
        public double CutRoadWidth { get; set; }
        //晶圆中心
        public Point WaferCenter { get; set; }
        /// <summary>
        /// 晶圆的厚度
        /// </summary>
        public double WaferThickness { get; set; }
        /// <summary>
        /// Die的总数
        /// </summary>
        public int DieCount { get; set; }
        public string ModelSavePath { get; set; }
        public string ExportPath { get; set; }
        public string MappingPath { get; set; }
        public string GetMappingFilterArgs()
        {
            return Path.Combine(ModelSavePath, "mappingFilter.zyn");
        }
        /// <summary>
        /// 获取子程式列表
        /// </summary>
        public List<string> GetSubprogramsDirName()
        {
            List<string> res = new List<string>();
            res.Add("");
            if (Directory.Exists(Path.Combine(ModelSavePath, "Subprograms")))
            {
                Directory.GetDirectories(Path.Combine(ModelSavePath, "Subprograms")).ToList().ForEach(v => res.Add(Path.GetFileNameWithoutExtension(v)));
            }
            return res;
        }
        /// <summary>
        /// 获取子程式
        /// </summary>
        /// <returns></returns>
        public TestProgramConfig GetSubprogram(string subprogram, string lan = "")
        {
            TestProgramConfig subPro;
            string name = "config.zyn";
            if (lan == "")
                subPro = JsonHelper.DeserializeByFile<TestProgramConfig>(Path.Combine(ModelSavePath, "Subprograms", subprogram, name));
            else
                subPro = JsonHelper.DeserializeByFile<TestProgramConfig>(Path.Combine(lan, "Subprograms", subprogram, name));
            if (ExportPath != null) subPro.ExportPath = Path.Combine(ExportPath, "Subprograms", subprogram);
            subPro.Id = Id;
            subPro.WaferCenter = WaferCenter;
            subPro.WaferRadius = WaferRadius;
            return subPro;
        }
        public string GetMappingFileName(string lan = "")
        {
            string name = "mapping.zyn";
            if (IsNonstandardMapping) name = "nonstandardMapping.zyn";
            if (lan == "")
                return Path.Combine(ModelSavePath, name);
            else
                return Path.Combine(lan, name);
        }
    }


}
